package com.eastedu.controller;

import com.eastedu.common.enums.DataSourceTypeEnum;
import com.eastedu.service.DataSourceManageService;
import org.springframework.http.HttpEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 学校组班信息接口
 *
 * @author Wu Gang
 */
@RestController
@RequestMapping(value = "/api/v1/data-sync")
public class DataSyncController {

    private final DataSourceManageService dataSourceManageService;

    public DataSyncController(DataSourceManageService dataSourceManageService) {
        this.dataSourceManageService = dataSourceManageService;
    }

    @PostMapping
    public HttpEntity<Boolean> questionSync(@RequestParam List<DataSourceTypeEnum> types) {
        this.dataSourceManageService.process(types);
        return ResponseEntity.ok(true);
    }

    @PostMapping("/scripts")
    public HttpEntity<Boolean> runScript(@RequestParam List<DataSourceTypeEnum> types, @RequestParam String stage) {
        this.dataSourceManageService.runScript(types, stage);
        return ResponseEntity.ok(true);
    }

}
